<template>
	<view class="container">
		<view class="orders-switch">
			<view class="item" :class=" showType == 0 ? 'active' : ''" @tap="switchTab" data-index='0'>
				<view class="txt">所有订单</view>
			</view>
			<view class="item " :class=" showType == 1 ? 'active' : ''" @tap="switchTab" data-index='1'>
				<view class="txt">有效订单</view>
			</view>
			<view class="item " :class=" showType == 2 ? 'active' : ''" @tap="switchTab" data-index='2'>
				<view class="txt">失效订单</view>
			</view>
			<view class="item" :class=" showType == 3 ? 'active' : ''" @tap="switchTab" data-index='3'>
				<view class="txt">已结算单</view>
			</view>
			<view class="item" :class=" showType == 4 ? 'active' : ''" @tap="switchTab" data-index='4'>
				<view class="txt">待结算单</view>
			</view>
		</view>
		<view class="no-order" v-if="orderList.length <= 0">
			<view class="c">
				<image src="/static/images/noCart_old.png" />
				<text>还没有任何订单呢</text>
			</view>
		</view>

		<view class="orders">
			<view class="order" open-type="redirect" v-for="(item,index) in orderList" :key="index">
				<view class="h">
					<view class="l">订单编号：{{item.orderSn}}</view>
					<view class="r">{{item.orderStatusText}}</view>
				</view>
				<view class="goods" v-for="(gitem,gindex) in item.goodsList" :key="gindex">
					<view class="img">
						<image :src="gitem.picUrl"></image>
					</view>
					<view class="info">
						<text class="name">{{gitem.goodsName}}</text>
					</view>
					<view class="status"></view>
				</view>
				<view class="b">
					<view class="l price">实付：￥{{item.actualPrice}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderList: [],
				showType: 0,
				page: 1,
				size: 10,
				totalPages: 1
			}
		},
		onLoad: function(options) {
			// 页面初始化 options为页面跳转所带来的参数
			let that = this
			try {
				var tab = that.$storage.getStorageSync('tab');

				that.showType = tab;
			} catch (e) {}

		},
		onReachBottom() {
			if (this.totalPages > this.page) {
				this.page = this.page + 1;
				this.getOrderList();
			} else {
				uni.showToast({
					title: '没有更多订单了',
					icon: 'none',
					duration: 2000
				});
				return false;
			}
		},
		methods: {
			getOrderList() {
				let that = this;
				that.$util.request(that.$api.api.SettleOrderList, {
					showType: that.showType,
					page: that.page,
					size: that.size
				}).then(function(res) {
					if (res.errno === 0) {
						console.log(res.data);
						that.orderList = that.orderList.concat(res.data.data);
						that.totalPages = res.data.totalPages;
					}
				});
			},
			switchTab: function(event) {
				let showType = event.currentTarget.dataset.index;
				this.orderList = [];
				this.showType = showType;
				this.page = 1;
				this.size = 10;
				this.totalPages = 1;
				this.getOrderList();
			},
		}
	}
</script>

<style>
	page {
		height: 100%;
		width: 100%;
		background: #f4f4f4;
	}

	.orders-switch {
		width: 100%;
		background: #fff;
		height: 84rpx;
		/* border-bottom: 1px solid rgba(0,0,0,.15); */
	}

	.orders-switch .item {
		display: inline-block;
		height: 82rpx;
		width: 18%;
		padding: 0 15rpx;
		text-align: center;
	}

	.orders-switch .item .txt {
		display: inline-block;
		height: 82rpx;
		padding: 0 20rpx;
		line-height: 82rpx;
		color: #9a9ba1;
		font-size: 30rpx;
		margin-left: 10rp;
		margin-right: 10rpx;
		width: 160rpx;
	}

	.orders-switch .item.active .txt {
		color: #85c43f;
		border-bottom: 3rpx solid #85c43f;
	}

	.no-order {
		width: 100%;
		height: auto;
		margin: 0 auto;
	}

	.no-order .c {
		width: 100%;
		height: auto;
		margin-top: 200rpx;
	}

	.no-order .c image {
		margin: 0 auto;
		display: block;
		text-align: center;
		width: 258rpx;
		height: 258rpx;
	}

	.no-order .c text {
		margin: 0 auto;
		display: block;
		width: 258rpx;
		height: 29rpx;
		line-height: 29rpx;
		text-align: center;
		font-size: 29rpx;
		color: #999;
	}

	.orders {
		height: auto;
		width: 100%;
		overflow: hidden;
	}

	.order {
		margin-top: 20rpx;
		background: #fff;
	}

	.order .h {
		height: 83.3rpx;
		line-height: 83.3rpx;
		margin-left: 31.25rpx;
		padding-right: 31.25rpx;
		border-bottom: 1px solid #f4f4f4;
		font-size: 30rpx;
		color: #333;
	}

	.order .h .l {
		float: left;
	}

	.order .h .r {
		float: right;
		color: #b4282d;
		font-size: 24rpx;
	}

	.order .goods {
		display: flex;
		align-items: center;
		height: 199rpx;
		margin-left: 31.25rpx;
	}

	.order .goods .img {
		height: 145.83rpx;
		width: 145.83rpx;
		background: #f4f4f4;
	}

	.order .goods .img image {
		height: 145.83rpx;
		width: 145.83rpx;
	}

	.order .goods .info {
		height: 145.83rpx;
		flex: 1;
		padding-left: 20rpx;
	}

	.order .goods .name {
		margin-top: 30rpx;
		display: block;
		height: 44rpx;
		line-height: 44rpx;
		color: #333;
		font-size: 30rpx;
	}

	.order .goods .number {
		display: block;
		height: 37rpx;
		line-height: 37rpx;
		color: #666;
		font-size: 25rpx;
	}

	.order .goods .status {
		width: 105rpx;
		color: #b4282d;
		font-size: 25rpx;
	}

	.order .b {
		height: 103rpx;
		line-height: 103rpx;
		margin-left: 31.25rpx;
		padding-right: 31.25rpx;
		border-top: 1px solid #f4f4f4;
		font-size: 30rpx;
		color: #333;
	}

	.order .b .l {
		float: left;
	}

	.order .b .r {
		float: right;
	}

	.order .b .btn {
		margin-top: 19rpx;
		height: 64.5rpx;
		line-height: 64.5rpx;
		text-align: center;
		padding: 0 20rpx;
		border-radius: 5rpx;
		font-size: 28rpx;
		color: #fff;
		background: #b4282d;
	}

	.price {
		font-size: 28rpx;
		color: #b4282d;
	}
</style>
